package com.amox.uitest.adapter;

import org.dom4j.Element;
import org.dom4j.Node;

import com.amox.uitest.common.KeyWord;
import com.amox.uitest.kit.LogKit;
import com.amox.uitest.kit.StrKit;
import com.amox.uitest.kit.XMLKit;
import com.amox.uitest.tcase.BaseTestCase;

public class LauchAdapter extends BaseAdapter<Boolean> {
	
	private FuncAdapter funcAdapter;
	
	public LauchAdapter(BaseTestCase uitest) {
		super(uitest);
		funcAdapter = new FuncAdapter(uitest);
	}
	
	@Override
	public Boolean adapter(Element element) throws Exception {
		String id = element.attributeValue(KeyWord.id.name());
		LogKit.printLog("Found Lauch : " + id);
		
		String value = StrKit.me().toSingleLine(element.getStringValue());
		String[] funcNames = value.split(";");
		for(String name : funcNames) {
			Node classNode = element.getParent();
			Node func = XMLKit.me(uitest).byAttr(classNode, KeyWord.func, KeyWord.id, name.trim());
			if(!funcAdapter.adapter((Element)func)) {
				return false;
			}
		}
		
		return true;
	}
}
